﻿/*
*   学员信息页面
*/
angular.module('jisuStuHome')
.controller('collectionListController', ['$scope', '$rootScope', '$state', 'StuRequestTrain', 'interlocutionservice', 'sysUserInfo', 'Msg', 'T', 'LS', function ($scope, $rootScope, $state, ST, IS, sysUserInfo, Msg, T, LS) {


    //初始
    $scope.init = function () {
        $rootScope.parstr = "home.interlocution";
        $rootScope.twoparstr = "home.interlocution.collectionquestion";
        //查询的参数
        $scope.params = {
            orgid: sysUserInfo.getuserinfo().organization_ID,
            userid:sysUserInfo.getuserinfo().user_ID,
            powerLV:sysUserInfo.getuserinfo().powerLV,
            searchTxt: "",
            pageIndex: 1,
            pageSize: 10,
            type:"3",
        };
        $scope.userInfo = sysUserInfo.getuserinfo(); //用户
        
    }
    
     //返回主页，专栏列表
    $scope.backHome = function () {
            $rootScope.twoparstr = "home.interlocution";
            $state.go($rootScope.twoparstr); 
    }
    $scope.init();
    //返回列表
    //路由跳转详情页面
    $scope.openQuestInfo = function (item) {
        $rootScope.twoparstr = "home.interlocution.questiondetail";
        LS.setLS(sysUserInfo.getuserinfo().user_ID + '_ques', item);
        $state.go($rootScope.twoparstr);
    }
    /**********************************查询***********************************/

    $scope.getList = function (index) {
        IS.findQuestionList($scope.params).then(function (response) {
            $scope.Loading = false;
            if (response.errorcode == "0") {
                $scope.List = response.datas;
                $scope.paginationConf.totalItems = response.numCount;
                $scope.paginationConf.currentPage = response.pageIndex;
            } else {
                Msg.error("查询异常!")
            }
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
    //取消收藏
    $scope.delCollection = function (item) {
        IS.delCollection({qaid:item.qaid,userid:sysUserInfo.getuserinfo().user_ID}).then(function (response) {
            $scope.Loading = false;
            if (response.errorcode == "0") {
                $scope.List.forEach(function(data,index){
                    if(data.qaid==item.qaid){
                        $scope.List.splice(index,1);
                    }
                })
            } else {
                Msg.error("操作异常!")
            }
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
    /*********************************************************************/
    //配置分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :  当前页码
        totalItems: 0,  // 总的记录数
        itemsPerPage: 10, // 每页显示多少条        
        perPageOptions: [10, 20],   // 每页显示记录数        
        onChange: function () {
            $scope.paginationConf.currentPage = $scope.paginationConf.currentPage == 0 ? 1 : $scope.paginationConf.currentPage;
            $scope.params.pageIndex = $scope.paginationConf.currentPage;
            $scope.params.pageSize = $scope.paginationConf.itemsPerPage;
            $scope.getList();
        }
    };

} ]);




